<template>
  <div class="videoList">
    <div class="list" v-if="data.length>0">
      <!-- <div class="item" v-for="item in data" :style="{width:'25%',height:height+'px'}">
        <FlvPlayer :url="item.url" v-if="item.state && item['state']!=='离线'"></FlvPlayer>
        <div class="offline" v-else></div>
        <p class="state">{{item.state}}</p>
      </div> -->

      <div class="main" v-if="isrefresh">
        <div class="section" v-for="(connectData, index) in data" :key="index">
          <onvif :xaddr="connectData.ip" :readonly="true" :user="connectData.username" :pass="connectData.password" :rtsp="connectData.videoAddress"
            :_width="640" :_height="height" :reConnect="true" class="onvif" @connect="connect" />
        </div>
      </div>
    </div>
    <div v-else style="color:#666; display: flex; align-items: center; justify-content: center"
      :style="{height:height*3+'px'}">
      查询结果为空！
    </div>
    <div class="page">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  // import FlvPlayer from "kkui/video/FlvPlayer";
  import onvif from "comp/onvif.vue";

  export default {
    name: "LiveList",
    components: {
      // FlvPlayer,
      onvif
    },
    props: ['data'],
    data() {
      return {
        isrefresh: true,
        connectDatas: [
          {
            xaddr: "172.16.16.70",
            user: "admin",
            pass: "zl@123456",
            rtsp: "rtsp://admin:zl@123456@172.16.16.70:554/Streaming/Channels/101",
          },
        ],
        width: 0,
        height: 0,
      }
    },
    watch: {
      data: {
        handler: function (n, o) {
          // console.log(this.isrefresh);
          // this.$forceUpdate();
        }
      }
    },
    mounted() {
      // console.log(this.data);
      this.init();
    },
    methods: {
      fanye() {
        this.isrefresh = this.isrefresh ? false :true;
        setTimeout(() => {
          this.isrefresh = this.isrefresh ? false :true;
        }, 100);
      },
      init() {
        const W = window.screen.width;
        this.width = W / 4;
        const elements = document.getElementsByClassName("list");
        // console.log(elements[0].offsetHeight);
        // this.height = W / 4 * 9 / 16 - 20;
        this.height = elements[0].offsetHeight / 2;
        console.log(this.height);
      },
      connect() {
        window.dispatchEvent(new Event('resize'))
      },
      close(msg) {
        window.dispatchEvent(new Event('resize'))
      },
      error(error) {
        window.dispatchEvent(new Event('resize'))
      },
    }
  }
</script>

<style scoped lang="scss">
  .main {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;

    .section {
      width: 640px;
      height: calc(100% / 2);
      /* min-height: 360px;
      max-height: calc(100% / 2); */
      flex: 33.3%;
      max-width: calc(100% / 3);
    }

    .onvif {
      width: 100%;
      height: 100%;
    }
  }

  .videoList {
    display: flex;
    flex-direction: column;
    height: 100%;

    .list {
      display: flex;
      flex-wrap: wrap;
      height: 100%;
      .item {
        border: 1px solid #000;
        box-sizing: border-box;
        position: relative;

        .offline {
          height: 100%;
          background-color: #333;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #ccc;
          font-weight: 600;
          font-size: 16px;
        }

        .name {
          position: absolute;
          bottom: 5px;
          left: 5px;
          text-align: center;
          font-size: 14px;
          font-weight: 600;
          text-shadow: -1px -1px 1px #333, 1px 1px 1px #999;
        }

        .state {
          position: absolute;
          top: 5px;
          right: 5px;
          text-align: center;
          font-size: 14px;
          font-weight: 600;
          color: #fff;
          text-shadow: -1px -1px 1px #333, 1px 1px 1px #000;
        }
      }
    }

    .page {
      min-height: 60px;
      flex: 1;
      display: flex;
      /*flex-direction: column;*/
      justify-content: center;
      text-align: center;
      align-items: center;
    }

    /deep/ .blackBg .el-pagination {
      .el-input__inner {
        background-color: #101010;
        border-color: rgba(255, 255, 255, .1);
        color: #006AA5;
        font-weight: 600;
      }

      .btn-next,
      .btn-prev {
        background: center center no-repeat #222;
        border: 1px solid #222;
        color: #555;
      }

      .btn-next:hover,
      .btn-prev:hover {
        color: var(--title-color)
      }

      button:disabled {
        color: #555 !important;
      }

      .el-pager li {
        background-color: #101010;
        border: 1px solid #111;
      }
    }
  }
</style>